package com.juzipi.demo.matest;

import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author juzipi
 * @Date 2021/5/11 17:12
 * @Info
 */
public class MapTest {

    public static void main(String[] args) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("1", "你好");
        hashMap.put("2", "你好1");
        hashMap.put("3", "你好2");
        hashMap.put("4", "你好3");
        hashMap.put("5", "你好4");
        hashMap.put("6", "你好5");
        hashMap.put("7", "你好6");
//        System.out.println(hashMap.size());
        ArrayList<Student> objects = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Student student = new Student();
            //LocalDate.of(2020,5, (int) (Math.random()*3))
            student.setWorkDate(LocalDate.now());
            student.setId((int) (Math.random() * 3));
            student.setAge((int) (Math.random() * 100));
            student.setName(RandomStringUtils.random(5, 'a', 'b'));
            objects.add(student);
        }
        objects.forEach(System.out::println);
        Map<Integer, List<Student>> collect = objects.stream().collect(Collectors.groupingBy(Student::getId));
        System.out.println(collect.size());

//        collect.forEach((k, v) -> {
//            System.out.println("k:" + k);
//        });
        HashMap<String, Object> map = new HashMap<>();


    }
}

class Student {
        int id;
        String name;
        int age;
        LocalDate workDate;

        public Student(int id, String name, int age) {
            this.id = id;
            this.name = name;
            this.age = age;
        }

        public Student(int id, String name, int age, LocalDate workDate) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.workDate = workDate;
        }

        public LocalDate getWorkDate() {
            return workDate;
        }

        public void setWorkDate(LocalDate workDate) {
            this.workDate = workDate;
        }

        public Student() {
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }